﻿using System;

namespace Shape2
{
    class Program
    {
        abstract class Shape
        {
            public double l;
            public double L
            {
                get { return l; }
                set { l = value; }
            }

            public double h;
            public double H
            {
                get { return h; }
                set { h = value; }
            }

            public double r;
            public double R
            {
                get { return r; }
                set { r = value; }
            }
            //area
            public abstract double Area();

            static void Main(string[] args)
            {
                double sumarea=0;
                //长方形
                Rectangle rectangle1 = new Rectangle();
               
                Rectangle rectangle2 = new Rectangle();
                
                Rectangle rectangle3 = new Rectangle();
               

                //正方形
                Square square1 = new Square();
                
                Square square2 = new Square();
               
                Square square3 = new Square();
                
                //三角形
                Triangle triangle1 = new Triangle();
                
                Triangle triangle2 = new Triangle();
                
                Triangle triangle3 = new Triangle();
                
                Triangle triangle4 = new Triangle();
                

                sumarea = rectangle1.Area() + rectangle2.Area() + rectangle3.Area() + square1.Area() + square2.Area() + square3.Area() + triangle1.Area() + triangle2.Area() + triangle3.Area() + triangle4.Area();
                Console.WriteLine("这10个几何图形的面积之和为："+sumarea);

            }
        }
        //长方形
        class Rectangle : Shape
        {
            
            public override double Area()
            {
                double sum = 0;
                Console.WriteLine("下面计算一个长方形的面积，请输入长：");
                L = double.Parse(Console.ReadLine());
                Console.WriteLine("请输入宽：");
                H = double.Parse(Console.ReadLine());
                sum = L * H;
                if (L > 0 && H > 0)
                {
                    Console.WriteLine("这个长方形的面积是：" + sum + "");
                }
                else
                {
                    Console.WriteLine("抱歉，您输入的长方形不合法。");
                }
                Console.ReadLine();
                return sum;
            }
        }
        //正方形
        class Square : Shape
        {
            public override double Area()
            {
                double sum = 0;
                Console.WriteLine("下面计算一个正方形的面积，请输入边长：");
                L = double.Parse(Console.ReadLine());
                sum = L * L;
                if (L > 0)
                {
                    Console.WriteLine("这个正方形的面积是：" + sum + "");
                }
                else
                {
                    Console.WriteLine("抱歉，您输入的正方形不合法。");
                }
                Console.ReadLine();
                return sum;
            }
        }
        //三角形
        class Triangle : Shape
        {
            public override double Area()
            {
                double sum = 0;
                Console.WriteLine("下面计算一个三角形的面积，请输入底：");
                L = double.Parse(Console.ReadLine());
                Console.WriteLine("请输入高：");
                H = double.Parse(Console.ReadLine());
                sum = 0.5 * L * H;
                if (L > 0 && H > 0)
                {
                    Console.WriteLine("这个三角形的面积是：" + sum + "");
                }
                else
                {
                    Console.WriteLine("抱歉，您输入的三角形不合法。");
                }
                Console.ReadLine();
                return sum;
            }
        }

    }
}